package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CCoupon
import com.onlyphoto.onlymall.mvp.model.MCouponImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.response.CouponBean


class PCouponImpl(mContext: Context, mView: CCoupon.IVCoupon) : BasePresenter<CCoupon.IVCoupon, MCouponImpl>(mContext, mView, MCouponImpl()), CCoupon.IPCoupon {
    override fun getStoreCoupons(get_type: Int) {
        mModel.getStoreCoupons(object :BaseObserver<ArrayList<CouponBean>>(mContext.get()){
            override fun onSuccess(data: ArrayList<CouponBean>?, msg: String?) {
                mView.getCouponsSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<CouponBean>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        }, get_type)
    }

    override fun getUserCoupons(get_type: Int, status: Int) {
        mModel.getUserCoupons(object :BaseObserver<ArrayList<CouponBean>>(mContext.get()){
            override fun onSuccess(data: ArrayList<CouponBean>?, msg: String?) {
                if (data == null) {
                    mView.showEmpty()
                }
                mView.getCouponsSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<CouponBean>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        }, get_type, status)
    }

    override fun receiveCoupon(couponId: Int, end_tm: Long) {
        mModel.receiveCoupon(object :BaseObserver<BaseEntity>(mContext.get()){
            override fun onSuccess(data: BaseEntity?, msg: String?) {
                mView.receiveCouponSuccess()
                mView.showToast("领取成功!")
            }

            override fun onCodeError(t: BaseNetworkResponse<BaseEntity>?) {
                mView.showToast(t?.msg!!)
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        }, couponId, end_tm)
    }
}
